﻿using ATM.DAO;
using ATM.Entities;
using System;
using System.Collections.Generic;
using System.Data;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ATM.BUS
{
    public class ValidationBUS
    {
        public static int ValidateCardID(string cardNo)
        {
            DataView tempDV = ValidateCardDAO.ValidateCardDataView();
            //tempDV.RowFilter = String.Format("CardNo like '{0}'", cardNo);

            for (int i = 0; i < tempDV.Table.Rows.Count; i++)
                if (tempDV.Table.Rows[i]["CardNo"].ToString() == cardNo)
                {
                    if (tempDV.Table.Rows[i]["Status"].ToString() == "0")
                        return 0;
                    else
                        return 1;
                }
            return 2;

        }
        

        public static int Authentication(Card card, string pass, int count)
        {
            //Console.WriteLine(card.PIN + "  " + pass);
            if (card.PIN != pass)
            {
                if (count < 3)
                {
                    card.Attempt += 1;
                    AuthenticateUserDAO.UpdateCard(card);
                    return 1;
                }
                else
                {
                    card.Attempt += 1;
                    card.Status = 0;
                    AuthenticateUserDAO.UpdateCard(card);
                    return 2;
                }
            }
            card.Attempt = 0;
            AuthenticateUserDAO.UpdateCard(card);
            return 0;
        }

        public static string GetCusName(Account acc)
        {
            return CustomerDAO.getCustomerName(acc);
        }
    }
}
